Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

191
Visualizações
canvas.toDataURL() returns [object Promise]

Can someone please tell me why canvas.toDataURL() shows [object Promise]? I want to load a node-canvas image on my website with an image tag in HTML. Here is my code:

Handlebars.registerHelper('updateImage', async function (id, user) {
    const welcome = new Keyv(`sqlite://data/welcome/${id}.sqlite`);
    const bgimg = await welcome.get('canvas-join-bgimg') ? await welcome.get('canvas-join-bgimg') : `https://i.imgur.com/XMPcnz1.jpeg`;

    const Canvas = require('canvas');

    const background = await Canvas.loadImage(bgimg);
    const avatardash = await Canvas.loadImage(user.displayAvatarURL({
        dynamic: true,
        size: 1024
    }));

    const canvas = Canvas.createCanvas(700, 250);
    const context = canvas.getContext('2d');

    context.drawImage(background, 0, 0, canvas.width, canvas.height);

    return new Handlebars.SafeString(
        '<img src='
        ' + canvas.toDataURL() + '
        ' />'
    );
});

Sorry, but I'm still learning, and I do not see anything of this on the web.

EDIT: Here you can see the result on my website:

Result

Any assistance would be greatly appreciated. Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is because you have not yet awaited the promise, therefore the promise is unresolved.

Awaiting the promise is simple, simply add the await keyword:

return new Handlebars.SafeString(
  `<img src="${await canvas.toDataURL()}">`
);

The above code is awaiting the promise and using template literals to avoid string concatenation.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda